package com.disruptor.disruptorStudy.demo03;

import java.nio.IntBuffer;

import com.disruptor.disruptorStudy.demo01.Trade;
import com.lmax.disruptor.RingBuffer;

public class Produces {

    private final RingBuffer<Trade> ringBuffer;

    public Produces(RingBuffer<Trade> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    //发布事件
    public void onData(IntBuffer buf) {
        //lambda写法:将传递的参数数据转换设置给event,消费者就直接消费event
        ringBuffer.publishEvent((event, sequeue, buffer) -> {
            event.setPrice(buffer.get(0));
        }, buf);
    }
}
